﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ControllerExtensibility.Infrastructure;
using ControllerExtensibility.Models;

namespace ControllerExtensibility.Controllers
{
    public class CustomerController : Controller
    {
        public ViewResult Index()
        {
            return View("Result", new Result
            {
                ControllerName = "Customer",
                ActionName = "Index"
            });
        }

        [Local]//prioriza los actions que estan marcados con ActionMethodSelectorAttribute
        [ActionName("Index")]
        public ActionResult LocalIndex()
        {
            return View("Result", new Result
            {
                ControllerName = "Home",
                ActionName = "LocalIndex"
            });
        }


        /*
         * 
            • You can then accept an action name that wouldn’t be legal as a C# method name
            (for example, [ActionName("User-Registration")]).
            • If you want to have two different C# methods that accept the same set of parameters
            and should handle the same action name, but in response to different HTTP request
            types (for example, one with [HttpGet] and the other with [HttpPost]), you can give
            the methods different C# names to satisfy the compiler,
         * */
        [ActionName("Enumerate")]
        public ViewResult List()
        {
            return View("Result", new Result
            {
                ControllerName = "Customer",
                ActionName = "List"
            });
        }

        protected override void HandleUnknownAction(string actionName)
        {
            Response.Write(string.Format("You requested the {0} action, but it's invalid", actionName));
        }
    }
}
